package com.zkzx.driver.controller;


import com.zkzx.common.driver.command.DriverCommand;
import com.zkzx.common.driver.model.DriverListVO;
import com.zkzx.common.driver.model.DriverVO;
import com.zkzx.common.driver.vo.DriverStatusVO;
import com.zkzx.common.exception.BaseException;
import com.zkzx.common.vo.PageResult;
import com.zkzx.common.vo.StatusVO;
import com.zkzx.driver.service.DriverService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 北京中科智兴物联科技有限公司 @版权所有
 *
 * @Author: zhaoyihe@zkraising.com
 * @Date: 2021/05/07/16:48
 * @Description:
 */
@RestController
@Validated
@Api( tags="司机基础服务")
@RequestMapping(value = "/drivers")
public class DriverController extends BaseController{

    @Autowired
    private DriverService driverService;



    @GetMapping
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取司机列表", notes = "获取司机列表")
    public PageResult<DriverListVO> find(@ApiParam(value = "查询参数") @RequestParam("filterParam") String filterParamJson,
                                         @ApiParam(value = "分页查询参数")  @RequestParam("params") String paramsJson) {

        return driverService.find(filterParamJson, paramsJson);
    }

    @GetMapping("/{id}")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取司机详细", notes = "获取司机详细")
    public DriverVO getById(@PathVariable("id") Integer id) {

        return driverService.getById(id,super.getCompanyId() );
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    @ApiOperation(value = "新增司机信息", notes = "新增司机信息")
    public StatusVO add(@RequestBody @Valid DriverCommand command) throws BaseException {

        return driverService.add(command,super.getUserId());
    }

    @PutMapping("/{id}")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "修改司机信息", notes = "修改司机信息")
    public void update(@PathVariable("id")Integer id,@RequestBody @Valid DriverCommand command) {

        driverService.update(command,id,super.getUserId());
    }



    @PostMapping("/{id}/verification")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取验证码", notes = "获取验证码")
    public DriverStatusVO verification(@PathVariable("id")Integer id) {

        return driverService.verification(id,super.getUserId(),super.getCompanyId());
    }

    @PostMapping("/{id}")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "提交", notes = "提交")
    public DriverStatusVO submit(@PathVariable("id")Integer id,@RequestParam("captcha")String  captcha)  {

        return driverService.submit(id,captcha,super.getUserId(),super.getCompanyId());
    }

    @PostMapping("/{id}/contract")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "邀请签约", notes = "邀请签约")
    public DriverStatusVO contract(@PathVariable("id")Integer id,@RequestParam("end_time")String endTime)  {
        return driverService.signContract(id,endTime,super.getUserId(),super.getCompanyId());
    }
}
